<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('第三方认证')"/>
    <th:block th:include="include :: select2-css"/>
    <style>
        .third-edit, .third-edit-box {
            display: none;
        }
    </style>
</head>
<body>
<div class="main-content">
    <form class="form-horizontal" id="form-third-edit" th:object="${third}">
        <input name="thirdId" type="hidden" th:field="*{thirdId}"/>
        <h4 class="form-header h4">API授权配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">clientId：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="clientId" type="text" th:field="*{clientId}"/>
                        <p class="form-control-plaintext third-view" th:text="*{clientId}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">clientSecret：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="clientSecret" type="text" th:field="*{clientSecret}"/>
                        <p class="form-control-plaintext third-view" th:text="*{clientSecret}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">是否签名：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid third-edit">
                            <input type="checkbox" id="sign" th:checked="${third.sign == 0}">
                            <span></span>
                        </label>
                        <p class="form-control-plaintext third-view" th:text="${third.sign == 0 ? '是' : '否'}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">是否加密：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid third-edit">
                            <input type="checkbox" id="enc" th:checked="${third.enc == 0}">
                            <span></span>
                        </label>
                        <p class="form-control-plaintext third-view" th:text="${third.enc == 0 ? '是' : '否'}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">加密方式：</label>
                    <div class="col-sm-8">
                        <div class="radio-box third-edit-box" th:each="dict : ${@dict.getType('sys_third_enc')}">
                            <input type="radio" th:id="${dict.dictCode}" name="encType" th:value="${dict.dictValue}"
                                   th:field="*{encType}">
                            <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                        <p class="form-control-plaintext third-view"
                           th:text="*{@dict.getLabel('sys_third_enc', encType)}"></p>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">第三方认证配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">认证地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="authUrl" type="text" th:field="*{authUrl}"/>
                        <p class="form-control-plaintext third-view" th:text="*{authUrl}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">目标服务地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="serverUrl" type="text" th:field="*{serverUrl}"/>
                        <p class="form-control-plaintext third-view" th:text="*{serverUrl}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">token地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="tokenUrl" type="text" th:field="*{tokenUrl}"/>
                        <p class="form-control-plaintext third-view" th:text="*{tokenUrl}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">用户信息地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="profileUrl" type="text" th:field="*{profileUrl}"/>
                        <p class="form-control-plaintext third-view" th:text="*{profileUrl}"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">渲染方式：</label>
                    <div class="col-sm-8">
                        <div class="radio-box third-edit-box" th:each="dict : ${@dict.getType('sys_third_render')}">
                            <input type="radio" th:id="${dict.dictCode}" name="render" th:value="${dict.dictValue}"
                                   th:field="*{render}">
                            <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                        <p class="form-control-plaintext third-view"
                           th:text="*{@dict.getLabel('sys_third_render', render)}"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">签发方式：</label>
                    <div class="col-sm-8">
                        <div class="radio-box third-edit-box" th:each="dict : ${@dict.getType('sys_third_issue')}">
                            <input type="radio" th:id="${dict.dictCode}" name="issueType" th:value="${dict.dictValue}"
                                   th:field="*{issueType}">
                            <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                        <p class="form-control-plaintext third-view"
                           th:text="*{@dict.getLabel('sys_third_issue', issueType)}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">当前服务地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="curUrl" type="text" th:field="*{curUrl}"/>
                        <p class="form-control-plaintext third-view" th:text="*{curUrl}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">签发地址(REDIRECT)：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="redirectIssueUrl" type="text"
                               th:field="*{redirectIssueUrl}"/>
                        <p class="form-control-plaintext third-view" th:text="*{redirectIssueUrl}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">签发地址(POST_MESSAGE)：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="postMessageIssueUrl" type="text"
                               th:field="*{postMessageIssueUrl}"/>
                        <p class="form-control-plaintext third-view" th:text="*{postMessageIssueUrl}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">签发地址(SOAP)：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="soapIssueUrl" type="text"
                               th:field="*{soapIssueUrl}"/>
                        <p class="form-control-plaintext third-view" th:text="*{soapIssueUrl}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">认证方式：</label>
                    <div class="col-sm-8">
                        <div class="third-edit">
                            <select name="authTypeList" class="form-control select2-multiple" multiple
                                    th:with="type=${@dict.getType('sys_third_auth_type')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:selected="${third.authTypeList.contains(dict.dictValue)}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                        <p class="form-control-plaintext third-view"
                           th:text="*{@dict.getMultiLabel('sys_third_auth_type', authTypeList)}"></p>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">同步回收配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">client_name：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="clientName" type="text" th:field="*{clientName}"/>
                        <p class="form-control-plaintext third-view" th:text="*{clientName}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">应用Id：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="appId" type="text" th:field="*{appId}"/>
                        <p class="form-control-plaintext third-view" th:text="*{appId}"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">应用密钥：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="appSecret" type="text" th:field="*{appSecret}"/>
                        <p class="form-control-plaintext third-view" th:text="*{appSecret}"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">密钥：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="dataKey" type="text" th:field="*{dataKey}"/>
                        <p class="form-control-plaintext third-view" th:text="*{dataKey}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">账号同步权限：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid third-edit">
                            <input type="checkbox" id="accountSync" th:checked="${third.accountSync == 0}">
                            <span></span>
                        </label>
                        <p class="form-control-plaintext third-view"
                           th:text="${third.accountSync == 0 ? '是' : '否'}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">SSO同步权限：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid third-edit">
                            <input type="checkbox" id="ssoSync" th:checked="${third.ssoSync == 0}">
                            <span></span>
                        </label>
                        <p class="form-control-plaintext third-view" th:text="${third.ssoSync == 0 ? '是' : '否'}"></p>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">API认证源配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">API密钥：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="apiKey" type="text" th:field="*{apiKey}"/>
                        <p class="form-control-plaintext third-view" th:text="*{apiKey}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">加密方式：</label>
                    <div class="col-sm-8">
                        <div class="radio-box third-edit-box" th:each="dict : ${@dict.getType('sys_third_enc')}">
                            <input type="radio" th:id="${dict.dictCode + 'api'}" name="apiEnc"
                                   th:value="${dict.dictValue}"
                                   th:field="*{apiEnc}">
                            <label th:for="${dict.dictCode + 'api'}" th:text="${dict.dictLabel}"></label>
                        </div>
                        <p class="form-control-plaintext third-view"
                           th:text="*{@dict.getLabel('sys_third_enc', apiEnc)}"></p>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">LDAP配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">LDAP服务IP：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="ldapIp" type="text" th:field="*{ldapIp}"/>
                        <p class="form-control-plaintext third-view" th:text="*{ldapIp}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">LDAP服务端口：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="ldapPort" type="text" th:field="*{ldapPort}"/>
                        <p class="form-control-plaintext third-view" th:text="*{ldapPort}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">用户名：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="username" type="text" th:field="*{username}"/>
                        <p class="form-control-plaintext third-view" th:text="*{username}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">密码：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="password" type="text" th:field="*{password}"/>
                        <p class="form-control-plaintext third-view" th:text="*{password}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">baseDn：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="baseDn" type="text" th:field="*{baseDn}"/>
                        <p class="form-control-plaintext third-view" th:text="*{baseDn}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">objectClass：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="objectClass" type="text"
                               th:field="*{objectClass}"/>
                        <p class="form-control-plaintext third-view" th:text="*{objectClass}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">LDAP账号属性：</label>
                    <div class="col-sm-8">
                        <input class="form-control third-edit" name="accountAttr" type="text"
                               th:field="*{accountAttr}"/>
                        <p class="form-control-plaintext third-view" th:text="*{accountAttr}"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">传输协议：</label>
                    <div class="col-sm-8">
                        <div class="radio-box third-edit-box"
                             th:each="dict : ${@dict.getType('sys_third_ldap_scheme')}">
                            <input type="radio" th:id="${dict.dictCode}" name="encType" th:value="${dict.dictValue}"
                                   th:field="*{ldapScheme}">
                            <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                        <p class="form-control-plaintext third-view"
                           th:text="*{@dict.getLabel('sys_third_ldap_scheme', ldapScheme)}"></p>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10 third-view">
        <button type="button" class="btn btn-sm btn-primary" shiro:hasPermission="system:third:edit"
                onclick="thirdEdit()"><i class="fa fa-edit"></i>编 辑
        </button>
    </div>
    <div class="col-sm-offset-5 col-sm-10 third-edit">
        <button type="button" class="btn btn-sm btn-primary" shiro:hasPermission="system:third:edit"
                onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="thirdClose()"><i class="fa fa-reply-all"></i>取 消
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var prefix = ctx + "system/third";

    var isEdit = false;

    function thirdEdit() {
        isEdit = true;
        $(".third-view").hide()
        $(".third-edit").show()
        $(".third-edit-box").css('display', 'inline-block')
    }

    function thirdClose() {
        isEdit = false;
        $(".third-edit").hide()
        $(".third-view").show()
        $(".third-edit-box").css('display', 'none')
    }

    function submitHandler() {
        var data = $("#form-third-edit").serializeArray();
        var sign = $("input[id='sign']").is(':checked') ? 0 : 1;
        var enc = $("input[id='enc']").is(':checked') ? 0 : 1;
        var accountSync = $("input[id='accountSync']").is(':checked') ? 0 : 1;
        var ssoSync = $("input[id='ssoSync']").is(':checked') ? 0 : 1;

        data.push({"name": "sign", "value": sign});
        data.push({"name": "enc", "value": enc});
        data.push({"name": "accountSync", "value": accountSync});
        data.push({"name": "ssoSync", "value": ssoSync});

        $.ajax({
            cache: true,
            type: "POST",
            url: prefix,
            data,
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.modal.msgSuccess(data.msg);
                window.location.reload()
            }
        });
    }

</script>
</body>
</html>